var api = require('../../util/api.js');
Page({
    data: {
        array: []
    },
    onLoad: function () {
        let _this = this;
        api.getDic('lhjd_type').then(res => {
            let index = 0;
            _this.setData({
                array: res,
                index: index,
                subType: res[index].dictValue
            });
        });
    },
    DateChange1: function (t) {
        this.setData({
            date1: t.detail.value
        });
    },
    DateChange2: function (t) {
        this.setData({
            date2: t.detail.value
        });
    },
    submit() {
        let _this = this;
        if (api.isBlank(this.data.khname)) {
            wx.showToast({
                title: '考核名称不能为空',
                icon: 'none'
            })
            return
        }
        if (api.isBlank(this.data.date1)) {
            wx.showToast({
                title: '开启时间不能为空',
                icon: 'none'
            })
            return
        }
        if (api.isBlank(this.data.date2)) {
            wx.showToast({
                title: '结束时间不能为空',
                icon: 'none'
            })
            return
        }
        api.post(api.url.examine, {
            subType: _this.data.subType,
            startTime: this.data.date1,
            finishTime: this.data.date2,
            name: this.data.khname
        }).then(res => {
            api.back('添加成功', 'none');
        });
    },
    khname(e) {
        this.setData({
            khname: e.detail.value
        })
    },
    bindPickerChange: function (e) {
        let _this = this;
        let index = e.detail.value;
        _this.setData({
            index: index,
            subType: _this.data.array[index].dictValue
        });
    }
});